package com.fulihui.wgj.admin.api.wxtemplate;

import com.fulihui.common.result.web.Result;
import com.fulihui.wgj.admin.api.base.BaseController;
import com.fulihui.wgj.admin.api.wxtemplate.request.WeiXinSinglePreviewRequest;
import com.fulihui.wgj.admin.integration.WxLocalTemplateServiceClient;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;

/**
 * @author: Levon
 * @date: 2018-07-26 15:54
 */
@RestController
@RequestMapping("/template")
@Api(tags = "模板消息发送到手机预览相关接口")
public class TemplateMsgPreviewController extends BaseController {

    @Autowired
    private WxLocalTemplateServiceClient wxLocalTemplateServiceClient;

    @RequestMapping(value = "/sendPre", method = RequestMethod.POST)
    @ApiOperation("发送到手机预览")
    public Result<Boolean> sendPre(@RequestBody @Valid WeiXinSinglePreviewRequest request, BindingResult validResult,
                                   HttpServletRequest servletRequest) {
        request.setAppId(getAppid(servletRequest));
        Result<Boolean> result = wxLocalTemplateServiceClient.singlePreview(request);
        return result;
    }
}
